//
//  FIAboutViewController.m
//  Magpie
//
//  Created by 100TV protocal on 12-11-13.
//
//

#import "FIAboutViewController.h"
#import "FIDataSourceFacade.h"
#import "FIHttpAPIHelper.h"
#import "FIRequestCheckVersion.h"

@interface FIAboutViewController ()

@end

@implementation FIAboutViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor redColor];
    
    NSString* appver = appVer();
	[FIDataSourceFacade requestCheckVersion:appver
                             clientPlatform:@"ipad"
                                     source:@"vancl_app_001"
                                     target:self
                                     action:@selector(checkVer:)];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#define UPDATE_ALERT 20
#define YK_URL_APP_STORE @"http://itunes.apple.com/cn/app/vancl-hd/id442666468?mt=8"

-(void)checkVer:(FIYYCheckVersion*)checkversion
{
    NSString* msg = @"";
	if (!isValidResponse(checkversion, &msg)){
		NSLog(@"!!!!warning checkver error: %@",checkversion);
		return;
	}
    //#warning测试数据
	self.updatever = checkversion;
	if (self.updatever != nil) {
		UIAlertView *updateAlert = [[UIAlertView alloc] initWithTitle:@"升级"
                                                              message:self.updatever.message
                                                             delegate:self
                                                    cancelButtonTitle:@"暂不"
                                                    otherButtonTitles:@"升级",nil];
		updateAlert.tag = UPDATE_ALERT;
		switch (self.updatever.versiontype) {
			case 0:
				//无升级
				break;
			case 1:
				//非强制升级
				[updateAlert show];
				[updateAlert release];
				break;
			case 2:
				//强制升级
				[[UIApplication sharedApplication] openURL:[NSURL URLWithString:YK_URL_APP_STORE]];
				break;
		}
	}
}

@end
